$(function(){
		//注册邮箱切换
		var c=0;
		// 单击事件
		$('.onlyone').click(function() {
			c++;

			if(c==2){
				left = 475*1;
				$('.usernameUl').css('left', left);
				c=0;
			}

			// 计算left值
			var left = -475*c;
			// 让大div移动到对应位置			
			$('.usernameUl').stop().animate({'left':left+'px'}, 700);
			$('.usernameUl ul li').find('input').val('');
			$('.emailalert').html('');
		
			
		});

		//验证码切换
		$('.changeCode').click(function() {
			$('.codeimg img').attr('src',code+'/code&num='+Math.random());
		});
		//表单input焦点事件 获取焦点事件
		$('input').focus(function() {
			$(this).css('border','1px solid #00AAFF');
			if($(this).val() == '请输入您的邮箱'){
				$(this).val('');
			}
		});
		//失去焦点事件
		$('input').blur(function() {			
			$(this).css('border','1px solid #DDDDDD');
			
		});
		//异步验证用户名是否存在
		$("input[name='email'],input[name='tel']").blur(
			function() {
			username = $(this).val();
			name = $(this).attr('name');			
			if(username == ''){			  	
			  	if($(this).attr('name') === 'email' && $(this).val()==''){				
					$(this).val('请输入您的邮箱');
					$('.emailalert').html('');
			  		$('.emailchoise').html('或<a >手机注册</a> ');
				}else{
					$(this).val('');
					$('.emailalert').html('');
			  		$('.emailchoise').html('或<a >邮箱注册</a> ');
				}
				$('.bg_reg_btn').attr("disabled","disabled");
				return false;
			}
			//正则验证手机号码和邮箱
			if(name == "email"){
				info ='邮箱';
				reg = /^[a-zA-Z]{1,16}[0-9A-Za-z_]{0,16}@[a-zA-Z0-9]{1,10}\.[a-z]{1,5}$/;
				if(!reg.test(username)){
					$('.emailalert').html('邮箱地址不正确');
					$('.onlyone').html('或<a >'+info+'注册</a> ');				
					$('.bg_reg_btn').attr("disabled","disabled");
					return false;
				}else{
					
					$('.onlyone').html('<span class="ok"></span>');
				
				
				}
			}else if(name == "tel"){				
				info = '手机';
				reg = /^[1]{1}[0-9]{10}$/;
				if(!reg.test(username)){
					$('.emailalert').html('手机号码格式不正确');
					$('.onlyone').html('或<a >'+info+'注册</a> ');
					$('.bg_reg_btn').attr("disabled","disabled");
					return false;
				}else{
					$('.onlyone').html('<span class="ok"></span>');
					
				}
			}
			
			$.ajax({
			   type: "POST",
			   url: code+"/checkUsername",
			   data: "username="+username,
			   success: function(msg){
			  
			  		if(msg == 0){
			  			$('.emailalert').html(info+'作为登录账号，方便您接收订单通知、找回密码等。');
			  			$('.onlyone').html('<span class="ok"></span>');
			  			
			  		}else{
			  			
			  			$('.emailalert').html('该'+info+'账号已注册');
			  			$('.onlyone').html('或<a >'+info+'注册</a> ');
			  			$('.bg_reg_btn').attr("disabled","disabled");
			  			return false;
			  		}
			   }
			});
		});

		$("input[name='password']").focus(function(){
			$('.passwordonly').html('密码设置至少6位以上，由数字、字母和符号混合而成，安全性最高');			
		})
		$("input[name='password']").blur(function(){

			password = $(this).val();
			if( password ==''){

				$('.passwordonly').html('密码设置至少6位以上，由数字、字母和符号混合而成，安全性最高');
				$('.bg_reg_btn').attr("disabled","disabled");
				return false;
			}else{

				reg = /\w{6,24}/;
				if(!reg.test(password)){
				
					$('.passwordonly').html('密码不够6位或者过于简单');
					$('.passwordchoiseOnly').html('');
					$('.bg_reg_btn').attr("disabled","disabled");
				}else{
					
					$('.passwordonly').html('');
					$('.passwordchoiseOnly').html('<span class="ok"></span>');
					if($(this).val() ==  $("input[name='password2']").val() &&  $(this).val() != ''  ){
			 			$('.password2alert').html('');
			 			
					}
				}
			}
						
		})
		//密码比对
		 $("input[name='password2']").blur(function(){
		 	if($(this).val() ==  $("input[name='password']").val() && $(this).val() != ''  ){
		 		$('.password2alert').html('');
		 		$('.passwordchoise').html('<span class="ok"></span>');
		 		$('.bg_reg_btn').attr("disabled",false);
		 	}else{
		 	
		 		$('.password2alert').html('两次密码不一致');
		 	
		 	}
		 })
		
		 $('.bg_reg_btn').click(function(){
		 	 //未填写禁止提交
 			if( $("input[name='password']").val()=='' || $("input[name='code']").val() =='' ){
 				$('.bg_reg_btn').attr("disabled","disabled");
				return false;				
			}
			//密码判断
			if( $("input[name='password']").val() ==  $("input[name='password2']").val() &&  $("input[name='password']").val() != ''  ){
		 		$('.bg_reg_btn').attr("disabled",false);
		 	}else{
		 		$('.bg_reg_btn').attr("disabled","disabled");
		 		return false;
		 	}

		 })
		 
		 	//验证码判断
		 	$("input[name='code']").blur(function(){
			 	if($("input[name='code']").val() !=''){
			 		codeval = $(this).val();
			 		$.ajax({
			 		   type:"POST",
					   url:code+'/checkCode',
					   data:'codeval='+codeval,
					   success: function(msg){
					   		if(msg == 0){
					   			$('.codealert').html('');
					   		}else{
					   			$('.codealert').html('验证码不正确');
					   			$('.bg_reg_btn').attr("disabled","disabled");		 		return false;
					   		}
					   }
			 		})
			 	}
		 	})
})// 文档结束符